window.onload=function (){
    var info= getQuery("errorInfo");
    if (info=="noland"){
        $("errorDiv").innerHTML="对不起，请先登录"
    }
    findAll()
}

function findAll(){
    axios.get("/class/findAll").then(resp=>{
        var info = resp.data;
        str="";
        info.forEach(n=>{
            str+=`<tr><td>${n.className}</td><td>${n.date}</td><td>${n.teacher}</td><td><input type="button" value="删除班级" onclick="delClass(${n.classId})"></td></tr>`
        })
        $("data").innerHTML=str;
    })
}

function delClass(classId){
    axios.get("/class/delClass",{
        params:{
            classId
        }
    }).then(resp=>{
        var info = resp.data;
        if (info=="ok"){
            findAll()
        }else {
            $("delDiv").style.visibility="visible"
        }
    })
}

function showAdd(){
    $("addDiv").style.visibility="visible"
}

function addClass(){
    axios.get("/class/addClass",{
        params: {
            className:$("className").value,
            teacher:$("teacher").value,
            date:$("date").value
        }
    }).then(resp=>{
        var info =resp.data;
        if (info=="ok"){
            exit()
            findAll()
        }
    })
}

function exit(){
    $("addDiv").style.visibility="hidden";
    $("delDiv").style.visibility="hidden";
}